import java.util.*;

public class Test {


    public static void main(String[] args) {
        CardDemo cardDemo = new CardDemo();
        //1. 买52张牌
        List<Card> cardList = cardDemo.buyCard();
        System.out.println(cardList);
        //2. 洗牌
        cardDemo.shuffle(cardList);
        System.out.println(cardList);
        //3. 3个人 每个人 轮流揭牌5张
        List<List<Card>> ret = cardDemo.play(cardList);

        for (int i = 0; i < ret.size(); i++) {
            System.out.println("第"+(i+1)+"个人的牌："+ret.get(i));
        }

        System.out.println("剩下的牌：");
        System.out.println(cardList);
    }

    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> list0 = new ArrayList<>();
        list0.add(1);
        ret.add(list0);
        //从第2行开始 进行求每个元素
        for (int i = 1; i < numRows; i++) {
            //处理第一个元素
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);
            //中间
            List<Integer> preRow = ret.get(i-1);
            for (int j = 1; j < i; j++) {
                int val1 = preRow.get(j);
                int val2 = preRow.get(j-1);
                curRow.add(val1+val2);
            }
            //尾巴
            curRow.add(1);
            ret.add(curRow);
        }
        return ret;
    }

    public static void main7(String[] args) {
        List<List<Integer>> ret = generate(4);
        for (int i = 0; i < ret.size(); i++) {
            for (int j = 0; j < ret.get(i).size(); j++) {
                System.out.print(ret.get(i).get(j)+" ");
            }
            System.out.println();
        }
    }
    public static void main6(String[] args) {
        List<List<Integer>> list = new ArrayList<>();
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list.add(list1);

        List<Integer> list2 = new ArrayList<>();
        list2.add(11);
        list2.add(21);
        list2.add(31);
        list.add(list2);


        System.out.println(list);

    }


    public static void main5(String[] args) {
        String str1 = "welcome to bit";
        String str2 = "come";
        ArrayList<Character> ret = new ArrayList<>();

        for (int i = 0; i < str1.length(); i++) {
            char ch = str1.charAt(i);
            if(!str2.contains(ch+"")) {
                ret.add(ch);
            }
        }
        for (int i = 0; i < ret.size(); i++) {
            System.out.print(ret.get(i));
        }
        System.out.println();
        //System.out.println(ret);
    }

    public static void main4(String[] args) {
        ArrayList<Integer> test = new ArrayList<>();
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(4);
        test.add(5);
        System.out.println(test);

        System.out.println("====使用迭代器 listIterator 输出   拓展===");
        ListIterator<Integer> it3 =  test.listIterator(test.size());
        while (it3.hasPrevious()) {
            System.out.print(it3.previous()+" ");
        }
        System.out.println();

        System.out.println("====使用迭代器iterator 输出===");
        Iterator<Integer> it =  test.iterator();
        while (it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();
        System.out.println("====使用迭代器 listIterator 输出===");
        ListIterator<Integer> it2 =  test.listIterator();
        while (it2.hasNext()) {
            System.out.print(it2.next()+" ");
        }
        System.out.println();
        int size = test.size();
        System.out.println("====for循环输出===");
        for (int i = 0; i < size; i++) {
            System.out.print(test.get(i)+" ");
        }
        System.out.println();
        System.out.println("====for each 循环输出===");
        for(Integer x : test) {
            System.out.print(x+" ");
        }
        System.out.println();





    }

    public static void main3(String[] args) {
        ArrayList<Integer> test = new ArrayList<>();
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(4);
        test.add(5);
        System.out.println(test);// 1 2 3 4 5

        List<Integer> list = test.subList(1,3); // 2 3
        System.out.println(list);

        System.out.println("=============");

        list.set(0,99);
        System.out.println(test);//1 2 3 4 5
        System.out.println(list);// 99 3

        /*
        [1, 99, 3, 4, 5]
        [99, 3]
         */

    }


    public static void main2(String[] args) {

        ArrayList<Integer> list = new ArrayList<>(12);
        list.add(11);
        list.add(31);
        list.add(51);


        ArrayList<Integer> test = new ArrayList<>();
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(1,99);
        test.addAll(list);
        System.out.println(test);//[1, 99, 2, 3, 11, 31, 51]

        test.remove(new Integer(99));
        System.out.println(test);



        ArrayList<Integer> ret = new ArrayList<>(list);



        List<Integer> list1 = new ArrayList<>();


    }

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            System.out.println(func(str));
        }
    }

    private static String func(String str) {
        boolean[] flg = new boolean[127];//默认都是false
        StringBuilder stringBuilder = new StringBuilder();
        for(int i = 0; i < str.length();i++) {
            char ch = str.charAt(i);
            if(flg[ch] == false) {
                stringBuilder.append(ch);
                flg[ch] = true;
            }
        }
        return stringBuilder.toString();
    }
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int i = m-1;
        int j = n-1;
        int k = m + n -1;

        while(i >= 0 && j >= 0) {
            if(nums1[i] > nums2[j]) {
                nums1[k--] = nums1[i--];
            }else {
                nums1[k--] = nums2[j--];
            }
        }

        // while(i >= 0 ) {
        //     nums1[k--] = nums1[i--];
        // }

        while( j >= 0 ) {
            nums1[k--] = nums2[j--];
        }

    }
}